<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" id="form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">更新时间</label>
                            <div class="layui-input-inline" style="width: 180px;">
                                <input type="text" name="dy_date1" id="dy_date1" autocomplete="off" class="layui-input">
                            </div>
                            <label style="float: left;padding-top: 4px;padding-right: 4px;">_&nbsp;&nbsp;</label>
                            <div class="layui-input-inline" style="width: 180px;">
                                <input type="text" name="dy_date2" id="dy_date2" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">标题查询</label>
                            <input type="text" id="dy_title" name="dy_title" autocomplete="off" class="layui-input"
                                style="width:300px">
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">正文查询</label>
                            <input type="text" id="dy_text" name="dy_text" autocomplete="off" class="layui-input"
                                style="width:300px">
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="dy-search-btn" style="margin-left:10px;width:100px;height:38px;border:none;outline:none;border-radius:6px;background-color:#007bff;color:white"><i
                                    class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <br>
        <div class="layui-btn-group">
            <button type="submit" id="addDynamicNew" class="layui-btn layui-btn-primary" lay-filter="data-add-btn"
                style="width:90px;height:38px;background-color:#FFB800;border:none;outline:none;color:white"> <i class="layui-icon layui-icon-form"></i>
                添加</button>
        </div>
        <table id="currentTableId" lay-filter="currentTableFilter"></table>
        <div id="page"></div>     
    </div>
    <script type="text/html" id="dyCurrentTableBar">
        <button class="layui-btn layui-btn-xs data-count-edit" lay-event="look">查看</button>
        <button class="layui-btn layui-btn-xs data-count-edit" lay-event="edit" style="background-color: #1E9FFF">编辑</button>
        <button class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" >删除</button>
    </script>
</div>
<style>
    .read{
    position: absolute;
    padding: 4px 4px;
    top: -4px;
    right: -4px;
    background-color: red;
    color: #ffffff;
    border-radius:50%;
    behavior: url('/lib/PIE/PIE.htc');
    z-index: 10;
}
</style>
<script>
    //form表单
    layui.form.render();

    //开始日期
    var today = new Date();
    var start = layui.laydate.render({
        elem: '#dy_date1',
        calendar: true,
        trigger: 'click',
        max: $("#dy_date1").val(),
        istime: true,
        istoday: true,
        done: function (value, date, endDate) {
            if (value != "") {
                end.config.min = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                }
            } else {//清空以后最小值
                end.config.min = {
                    year: 1970,
                    month: 1,
                    date: 1,
                }
            }
        }
    });

    //结束日期
    var end = layui.laydate.render({
        elem: '#dy_date2',
        calendar: true,
        trigger: 'click',
        max: $("#dy_date2").val(),
        istime: true,
        istoday: true,
        done: function (value, date) {
            if (value != "") {
                start.config.max = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                }
            } else {//清空以后最大值
                start.config.max = {
                    year: today.getFullYear(),
                    month: today.getMonth(),
                    date: today.getDate()
                }
            }
        }
    });


     //初始化table
    var form = layui.form,
        laydate = layui.laydate,
        table = layui.table,
        cols = [
            { align: 'center', title: '序号', type: 'numbers', width: '5%' },
            { field: 'id', title: 'ID', width: '8%', hide: true },
            { field: 'title', title: '标题', align: 'center', width: '30%' },
            { field: 'source', title: '来源', align: 'center', width: '15%' },      
            { field: 'sendTime', title: '发布时间', align: 'center' ,width: '10%'},
            { field: 'entryPerson', title: '录入人ID', align: 'center', hide: true },
            { field: 'entryPersonName', title: '录入人', align: 'center', width: '10%' },
            // { field: 'text', title: '正文', align: 'center', width: '25%' },
            // { field: 'creatTime', title: '创建时间', align: 'center', width: '15%' },
            { field: 'updateTime', title: '更新时间',  align: 'center', width: '12%'  },
            { title: '操作', templet: '#dyCurrentTableBar',  align: "center",width: '18%' }
        ];

        layuiEx.tableRender('/admin/dynamicNews/queryDynamicNews', 'currentTableId', 'page', cols, {
            page: 1,
            pageSize: 10,
        });

    // 监听搜索操作
     form.on('submit(dy-search-btn)', function (data) {
        startTime = $("#dy_date1").val(),
        endTime = $("#dy_date2").val(),
        searchTitle = $("#dy_title").val();
        searchText = $("#dy_text").val();
        layuiEx.tableRender('/admin/dynamicNews/queryDynamicNews', 'currentTableId', 'page', cols, {
            startTime: startTime,
            endTime: endTime,
            searchTitle: searchTitle,
            searchText: searchText,
            page: 1,
            pageSize: 10
        });
        return false;
    });

       // 监听添加动态新闻按钮
       $("#addDynamicNew").on("click", function () {
         var content = layui.miniPage.getHrefContent('mypages/messageManagement/dynamicNews_add.html');
         var openWH = layui.miniPage.getOpenWidthHeight();
        var index = layer.open({
            title: '添加动态新闻',
            type: 1,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            zIndex:1000,
            area: ['1200px', '95%'],
            // area: ['60%', '95%'],
            // offset: [openWH[2] + 'px', openWH[3] + 'px'],
            content: content,
        });
        $(window).on("resize", function () {
            layer.full(index);
        });
        return false;
    });

     //监听删除和编辑操作
     layui.table.on('tool(currentTableFilter)', function (obj) {
        var data = obj.data;
        if (obj.event === 'edit') {
            editData = obj.data;
            var content = layui.miniPage.getHrefContent('mypages/messageManagement/dynamicNews_edit.html');
            var openWH = layui.miniPage.getOpenWidthHeight();
            var index = layer.open({
                title: '编辑动态新闻',
                type: 1,
                shade: 0.2,
                maxmin: true,
                zIndex:1000,
                shadeClose: true,
                area: ['1200px', '90%'],
                // area: ['1200px', '750px'],
                content: content,
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        } else if (obj.event === 'delete') {
            layer.confirm('确定删除？', function (index) {
                deltDate = obj.data;
                shared.ajaxPost('/admin/dynamicNews/delDynamicNews', deltDate, function (res) {
                    dyRefreshTable();
                },{async : false})
                layer.close(index);
            });
        } else if (obj.event === 'look') {
            editData = obj.data;
            var content = layui.miniPage.getHrefContent('mypages/messageManagement/dynamicNews_look.html');
            var openWH = layui.miniPage.getOpenWidthHeight();
            var index = layer.open({
                title: '查看动态新闻',
                type: 1,
                shade: 0.2,
                maxmin: true,
                zIndex:1000,
                shadeClose: true,
                area: ['1200px', '90%'],
                // area: ['1200px', '750px'],
                content: content,
            });
            $('.layui-layer-shade').css('z-index','1000')
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        }
    });

    function dyRefreshTable(){
        cols = [
            { align: 'center', title: '序号', type: 'numbers', width: '5%' },
            { field: 'id', title: 'ID', width: '8%', hide: true },
            { field: 'title', title: '标题', align: 'center', width: '30%' },
            { field: 'source', title: '来源', align: 'center', width: '15%' },      
            { field: 'sendTime', title: '发布时间', align: 'center' ,width: '10%'},
            { field: 'entryPerson', title: '录入人ID', align: 'center', hide: true },
            { field: 'entryPersonName', title: '录入人', align: 'center', width: '10%' },
            // { field: 'text', title: '正文', align: 'center', width: '25%' },
            // { field: 'creatTime', title: '创建时间', align: 'center', width: '15%' },
            { field: 'updateTime', title: '更新时间',  align: 'center', width: '12%'  },
            { title: '操作', templet: '#dyCurrentTableBar',  align: "center",width: '18%' }
        ];

        layuiEx.tableRender('/admin/dynamicNews/queryDynamicNews', 'currentTableId', 'page', cols, {
            page: 1,
            pageSize: 10,
        });
    }

    function getImage(thisImg,path, parameter) {             
        thisImg.src = config.server + "/" + path + "/" + parameter;
        thisImg.onerror = null;
    }

    function getFile(path,parameter){
        var url = config.server + "/" + path + "/" + parameter;
        window.location.href = url;
     }

     
</script>